package com.first.teacher.controller;

import com.first.common.pojo.EduVideo;
import com.first.common.vo.Result;
import com.first.teacher.service.VideoService;
import com.first.teacher.vo.InsertVideoVo;
import com.first.teacher.vo.UpdataVideoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: finrsteducation-parent
 * @description: 视频管理
 * @author: 张玉森
 * @create: 2023-06-08 16:05
 **/
@RestController
@RequestMapping("/core/video")
@Api(tags = "视频管理接口")
public class VideoController {
    @Autowired
    private VideoService videoService;

    @DeleteMapping("deleteById/{id}/{sort}/{chapterId}")
    @ApiOperation("删除章节的内容")
    public Result deleteById(@PathVariable String id,
                             @PathVariable Integer sort,
                             @PathVariable String chapterId) {
        Integer delete=videoService.deleteVideoById(id,sort,chapterId);
        if (delete==1){
            return Result.success();
        }
        return Result.fail("删除章节的内容失败");
    }

    @PostMapping("updateVideo")
    @ApiOperation("修改章节的内容")
    public Result updateVideo(@RequestBody UpdataVideoVo updateVo) {
        Integer update = videoService.updateVideo(updateVo);
        if (update == 1) {
            return Result.success();
        }
        return Result.fail("修改章节的内容失败");
    }

    @PutMapping("insertVideo")
    @ApiOperation("上传章节的内容")
    public Result insertVideo(@RequestBody InsertVideoVo insertVideoVo) {
        Integer integer = videoService.insertVideo(insertVideoVo);
        return Result.success();
    }

    @GetMapping("findAllVideo/{videoId}")
    @ApiOperation("根据章节ID查询章节信息")
    public Result findAllVideo(@PathVariable String videoId) {
        List<EduVideo> eduVideo = videoService.findAllVideo(videoId);
        return Result.success(eduVideo);
    }

    @DeleteMapping("findAllVideo/{Id}/{sort}/{chapter_id}")
    @ApiOperation("根据章节ID查询章节信息")
    public Result deleteById(@PathVariable String Id) {
        Integer integer = videoService.deleteById(Id);
        return Result.success(integer);
    }
}